using System;
using System.Windows.Forms;

using FreeFlow.Administration;

namespace FreeFlowAdministrator
{
	/// <summary>
	/// Summary description for RolesAdaptor.
	/// </summary>
	public class RolesAdaptor : Adaptor, IRefreshable
	{
    private RoleCollection roles;
		public RolesAdaptor(RoleCollection roles)
		{
      this.roles = roles;
    }

    public override void AddChildren(System.Windows.Forms.TreeNode node)
    {
      foreach (Role role in roles)
      {
        TreeNode childNode = TreeNodeFactory.CreateTreeNode(new RoleAdaptor(role));
        node.Nodes.Add(childNode);
      }
    }

    public override int ImageIndex
    {
      get
      {
        return 6;
      }
    }

    public override string Text
    {
      get
      {
        return "Roles (" + roles.Count + ")";
      }
    }

    public override Control GetRenderer()
    {
      RolesControl control = new RolesControl();
      control.LoadRoles(roles);
      control.RefreshRequired += new EventHandler(TriggerRefreshRequired);
      return control;
    }

    public override object Object
    {
      get
      {
        return roles;
      }
    }

    #region IRefreshable Members

    public void Refresh()
    {
      roles.Refresh();
    }

    #endregion
  }
}
